<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>

<?php
$type = $_GET["type"];
session_start();
$s_user=$_SESSION["s_user"];

include("../app/connection.php");
require_once("Export.php");
if(isset($type) && $type!="")
{
	if($type=="dkhp")
	{
		$time = date("Y-m-d");
		require_once("exportForm.php");
		$query = "select HOCKY,NAM from HOCKY where NGAYBATDAU < '$time' and NGAYKETTHUC > '$time'";
		$result = mysql_query($query);
		$row = mysql_fetch_array($result);
		if($row!=false)
		{
			$year=$row[1];
			$semeter=$row[0];
			echo "<center><h1>Phiếu Đăng Ký Học Phần Học Kỳ $semeter Năm Học $year</h1></center>";
			$obj = new getForm();
			$result = mysql_query("select * from SINHVIEN where MSSV = '$s_user'");
			$row = mysql_fetch_array($result);
			$num = mysql_num_fields($result);
			for($i=0;$i<$num;$i++)
			{
				if(mysql_fetch_field($result,$i)->name=="GIOITINH")
				{
					if($row[$i]==0)
					{
						echo "<b>".$obj->convert(mysql_fetch_field($result,$i)->name)."</b>"."      :        Nam<br>";
					}
					else
					{
						 echo "<b>".$obj->convert(mysql_fetch_field($result,$i)->name)."</b>"."      :        Nữ<br>";
					}
				}
				else if(mysql_fetch_field($result,$i)->name=="PASSWORD"||mysql_fetch_field($result,$i)->name=="TRANGTHAI")
				{
				}
				else
				{
					echo "<b>".$obj->convert(mysql_fetch_field($result,$i)->name)."</b>"."      :        ".$row[$i]."<br>";
				}
			}
			$result = mysql_query("select DANGKY.MALOP,MONHOC.MAMONHOC,TENMONHOC,TINCHILYTHUYET,TINCHITHUCHANH from DANGKY,MONHOC where DANGKY.MAMONHOC = MONHOC.MAMONHOC and DANGKY.MSSV='$s_user' and DANGKY.HOCKY=$semeter and DANGKY.NAM='$year'");
			echo "<br><br><table>";
			echo "<tr>";
			$obj = new getForm();
			while($colTit = mysql_fetch_field($result))
			{
				echo "<td>";
				echo $obj->convert($colTit->name);
				echo "</td>";
			}
			echo "<tr>";
			while($row = mysql_fetch_assoc($result))
			{
				echo "<tr>";
				foreach($row as $val)
				{
					echo "<td>$val</td>";
				}
				echo "</tr>";
			}
			echo "</table>";
		}
		else
		{
			echo "Thời Gian Hiện Tại Không Thuộc Học Kì nào";
		}
	}
	if($type=="info")
	{
		require_once("exportform.php");
		$obj = new getForm();
		echo "<center><h1>Trang Thông Tin Sinh Viên</h1></center>";
		$result = mysql_query("select * from SINHVIEN where MSSV = '$s_user'");
		$row = mysql_fetch_array($result);
		$num = mysql_num_fields($result);
		for($i=0;$i<$num;$i++)
		{
			if(mysql_fetch_field($result,$i)->name=="GIOITINH")
			{
				if($row[$i]==0)
				{
					echo "<b>".$obj->convert(mysql_fetch_field($result,$i)->name)."</b>"."      :        Nam<br>";
				}
				else
				{
					 echo "<b>".$obj->convert(mysql_fetch_field($result,$i)->name)."</b>"."      :        Nữ<br>";
				}
			}
			else if(mysql_fetch_field($result,$i)->name=="PASSWORD"||mysql_fetch_field($result,$i)->name=="TRANGTHAI")
			{
			}
			else
			{
				echo "<b>".$obj->convert(mysql_fetch_field($result,$i)->name)."</b>"."      :        ".$row[$i]."<br>";
			}
		}
		$result = mysql_query("select TENKHOA from KHOA where KHOA.MAKHOA = '$row[4]'");
		$row = mysql_fetch_array($result);
		echo "<b>".$obj->convert(mysql_fetch_field($result,0)->name)."</b>"."      :        ".$row[0]."<br>";
	}
	if($type=="result")
	{
		require_once("exportForm.php");
		$obj = new getForm();
		echo "<center><h1>Kết Quả Học Tập Sinh Viên</h1></center>";
		$result = mysql_query("select * from SINHVIEN where MSSV = '$s_user'");
		$row = mysql_fetch_array($result);
		$num = mysql_num_fields($result);
		for($i=0;$i<$num;$i++)
		{
			if(mysql_fetch_field($result,$i)->name=="GIOITINH")
			{
				if($row[$i]==0)
				{
					echo "<b>".$obj->convert(mysql_fetch_field($result,$i)->name)."</b>"."      :        Nam<br>";
				}
				else
				{
					 echo "<b>".$obj->convert(mysql_fetch_field($result,$i)->name)."</b>"."      :        Nữ<br>";
				}
			}
			else if(mysql_fetch_field($result,$i)->name=="PASSWORD"||mysql_fetch_field($result,$i)->name=="TRANGTHAI")
			{
			}
			else
			{
				echo "<b>".$obj->convert(mysql_fetch_field($result,$i)->name)."</b>"."      :        ".$row[$i]."<br>";
			}
		}
		echo "<br><br><table style='boder-spacing:0px;border-top:1px solid black;border-left:1px solid black'>";
		echo "<tr>";
		$result = mysql_query("select KETQUA.MAMONHOC,TENMONHOC,DIEMGIUAKY,DIEMTHUCHANH,DIEMCUOIKY from KETQUA,MONHOC where MONHOC.MAMONHOC = KETQUA.MAMONHOC and KETQUA.MSSV = '$s_user'");
		while($colTit = mysql_fetch_field($result))
		{
			echo "<td style='border-bottom:1px solid black;border-right:1px solid black'>";
			echo $obj->convert($colTit->name);
			echo "</td>";
		}
		echo "<tr>";
		$year= mysql_query("select distinct NAM from KETQUA where MSSV='$s_user' order by NAM asc");
		while($row = mysql_fetch_array($year))
		{
			
			$semeter = mysql_query("select distinct HOCKY from KETQUA where MSSV='$s_user' and NAM='$row[0]' order by HOCKY asc");
			{
				while($r = mysql_fetch_array($semeter))
				{
					$result = mysql_query("select KETQUA.MAMONHOC,TENMONHOC,DIEMGIUAKY,DIEMTHUCHANH,DIEMCUOIKY from KETQUA,MONHOC where MONHOC.MAMONHOC = KETQUA.MAMONHOC and KETQUA.MSSV = '$s_user' and KETQUA.NAM='$row[0]' and KETQUA.HOCKY=$r[0]");
					echo "<tr>";
					echo "<th style='text-align:left;border-bottom:1px solid black;border-right:1px solid black' colspan='6'>Học Kỳ $r[0] - Năm Học $row[0]</th>";
					echo "</tr>";
					$num = mysql_num_fields($result);
					while($val = mysql_fetch_array($result))
					{
						echo "<tr>";
						for($i=0;$i<$num;$i++)
						{
							echo "<td style='border-bottom:1px solid black;border-right:1px solid black'>$val[$i]</td>";
						}
						echo "</tr>";
					}
				}
			}
		}
		echo "</table>";
	}
	if($type=="tkb")
	{
		require_once("/TKB/tkb.php");
		$time = date("Y-m-d");
		$query = "select * from HOCKY where NGAYBATDAU < '$time' and NGAYKETTHUC > '$time'";
		$result = mysql_query($query);
		if($row = mysql_fetch_array($result))
		{
			$semter=$row[0];
			$year = $row[1];
			require_once("exportform.php");
			$temp = new getForm();
			$result = mysql_query("select * from SINHVIEN where MSSV = '$s_user'");
			$row = mysql_fetch_array($result);
			$num = mysql_num_fields($result);
			for($i=0;$i<$num;$i++)
			{
				if(mysql_fetch_field($result,$i)->name=="GIOITINH")
				{
					if($row[$i]==0)
					{
						echo "<b>".$temp->convert(mysql_fetch_field($result,$i)->name)."</b>"."      :        Nam<br>";
					}
					else
					{
						 echo "<b>".$temp->convert(mysql_fetch_field($result,$i)->name)."</b>"."      :        Nữ<br>";
					}
				}
				else if(mysql_fetch_field($result,$i)->name=="PASSWORD"||mysql_fetch_field($result,$i)->name=="TRANGTHAI")
				{
				}
				else
				{
					echo "<b>".$temp->convert(mysql_fetch_field($result,$i)->name)."</b>"."      :        ".$row[$i]."<br>";
				}
			}
			echo "<br><br>";
			$obj = new tbk();
			$obj->personalTKB("$s_user",$semter,$year);
		}
	}
}
?>
</body>
</html>